const { app, BrowserWindow } = require('electron')
const path = require('path')
const WinState = require("electron-win-state").default
// 获取网站信息
require('./controller/getSource')
//alert 弹框
require('./controller/alert')


const createWindow = () => {
  const winState = new WinState({
    defaultWidth: 1000,
    defaultHeight: 800,
  })

  const win =  new BrowserWindow({
    ...winState.winOptions,  //自定义窗口状态
    webPreferences: { 
      preload: path.resolve(__dirname, './preload')  //预加载JS文件
    }
  })

  win.loadURL("http://localhost:3000")  //加载界面

  win.webContents.openDevTools()    //打卡调试工具

  winState.manage(win)

}

app.whenReady().then(()=> {
  createWindow()

  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow();
    }
  })
})


app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
})